from flask import Flask, render_template
import viewdata.tools as tool
from flask import jsonify, json
from flask_cors import CORS

app = Flask(__name__, static_folder='', static_url_path='')
CORS(app, resources='/*')
app.config['JSON_AS_ASCII'] = False
app.config['JSONIFY_PRETTYPRNT_REGULAR'] = False
app.config['JSON_SORT_KEYS'] = False

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/index2")
def index2():
    return render_template("index2.html")

@app.route("/index3")
def index3():
    return render_template("index3.html")

@app.route("/bigdata")
def index4():
    return render_template("bigdata.html")

@app.route("/survey")
def index5():
    return render_template("survey.html")

@app.route("/bigdata/toplist")
def task():
    data = tool.bigdata_toplist()
    return jsonify({"data": data})

@app.route("/bigdata/company")
def task2():
    data = tool.bigdata_company()
    return jsonify(data)

@app.route("/bigdata/chart3")
def task3():
    data = tool.bigdata_chart3()
    return jsonify(data)

@app.route("/bigdata/sales_rank")
def task4():
    data = tool.bigdata_sales_rank()
    return jsonify(data)

@app.route("/bigdata/chart2")
def task5():
    data = tool.bigdata_chart2_data()
    y_data = data[0]
    x_data = data[1]
    return jsonify({"ydata": y_data, "xdata": x_data})

@app.route("/bigdata/ceshi5")
def task6():
    data = tool.bigdata_ceshi5_data()
    return jsonify({"data1": data[0], "data2": data[1], "data3": data[2], "data4": data[3], "data5": data[4], "data6": data[5]})

@app.route("/bigdata/chart4")
def task7():
    data = tool.bigdata_chart4_data()
    return jsonify({"monthvalue": data[0], "ordervalue": data[1], "pays": data[2], "avgs": data[3]})

@app.route("/bigdata/chart5")
def task8():
    data = tool.bigdata_chart5_data()
    return jsonify({"CountryName": data[0], "CountryValue": data[1]})

@app.route("/js/data-1482909892121-BJ3auk-Se.json", methods=['GET'])
def survey_json_get():
    with open(r"C:\Users\86186\PycharmProjects\FlaskProject2\Viewdata-master\statics\js\data-se.json", encoding='utf-8') as f:
        jsonStr = json.load(f)
        return json.dumps(jsonStr)

@app.route("/survey/top_list")
def task9():
    data = tool.survey_basic_info_data()
    return jsonify(data)

@app.route("/survey/shop_info")
def task10():
    data = tool.survey_shop_info_data()
    return jsonify(data)

@app.route("/survey/shop_basic")
def task11():
    data = tool.survey_shop_basic_data()
    return jsonify(data)

@app.route("/survey/chart3")
def task12():
    data = tool.survey_chart3()
    return jsonify(data)

@app.route("/survey/chart2")
def task13():
    data = tool.survey_chart2_data()
    y_data = data[0]
    x_data = data[1]
    return jsonify({"ydata": y_data, "xdata": x_data})

@app.route("/survey/chart5")
def task14():
    data = tool.survey_chart5_data()
    return jsonify({"Names": data[0], "Values": data[1]})

@app.route("/survey/shuiipin")
def task15():
    data = tool.survey_shuiipin_data()
    return jsonify(data)

@app.route("/survey/diqu")
def task16():
    data = tool.survey_diqu_data()
    return jsonify(data)

@app.route("/survey/chart4")
def task17():
    data = tool.survey_chart4_data()
    return jsonify({"data1": data[0], "data2": data[1], "data3": data[2], "data4": data[3], "thedate": data[4]})

@app.route("/index2/toplist")
def task18():
    data = tool.index2_toplist()
    return jsonify(data)

@app.route("/index2/chart")
def task19():
    data = tool.index2_chart_data()
    return jsonify(data)

@app.route("/index2/top_title")
def task20():
    data = tool.index2_toptitle()
    return jsonify(data)

@app.route("/js/data-1576140623415-kSH4vRQ1.json", methods=['GET'])
def index3_json_get():
    with open(r"C:\Users\86186\PycharmProjects\FlaskProject2\Viewdata-master\statics\js\data-1576140623415-kSH4vRQ1.json", encoding='utf-8') as f:
        jsonStr = json.load(f)
        return json.dumps(jsonStr)

@app.route("/index3/char1_2")
def task21():
    data = tool.index3_char1_2_data()
    return jsonify({"char1_name":data[0],"char1_value":data[1],"char2_name":data[2],"char2_value":data[3]})

@app.route("/index3/char3")
def task22():
    data = tool.index3_char3_data()
    return jsonify({"province":data[0],"damaged":data[1],"lost":data[2],"rejects":data[3],"not_signed":data[4]})

@app.route("/index3/maps")
def task23():
    data = tool.index3_maps_data()
    return jsonify(data)

@app.route("/index3/chart5")
def task24():
    data = tool.index3_chart5_data()
    return jsonify({"sex_data":data[0],"line_old":data[1],"line_value":data[2],"edu_data":data[3]})

@app.route("/index3/chart6")
def task25():
    data = tool.index3_chart6_data()
    return jsonify({"data1":data[0],"data2":data[1]})

@app.route("/index3/chart8")
def task26():
    data = tool.index3_chart8_data()
    return jsonify(data)

if __name__ == '__main__':
    app.debug = True
    app.run()